<!--
 * @Description: 字典类型
 * @Author: Liu Zhiwang
 * @Date: 2021-04-09 11:49:17
 * @LastEditTime: 2022-03-15 18:15:56
 * @LastEditors: Please set LastEditors
-->
<template>
  <div class="app-container v-flex">
    <filter-form :form="listQuery" :data="filterData" only-query @search="search">
      <el-button
        class="refresh-btn"
        size="mini"
        type="primary"
        icon="el-icon-refresh"
        @click="resetListQuery">重置</el-button>

    </filter-form>

    <!-- 表格 -->
    <div ref="main" class="v-flex-elastic">
      <base-table
        :height="height"
        :loading="tableData.loading"
        :data="tableData.tableList"
        :columns="tableData.columns"
        :show-index="tableData.showIndex"
        :show-selection="tableData.showSelection"
        :show-operation="tableData.showOperation"
        :show-filter-column="tableData.showFilterColumn"
        :operaton-width="tableData.operatonWidth"
        :default-operations="tableData.defaultOperations"
        :has-auth="tableData.hasAuth"
        :row-show-color="tableData.rowShowColor" />
    </div>
    <!-- 表格 -->

    <!-- 分页 -->
    <div class="page-box">
      <pagination
        :total="tableData.total"
        :page.sync="listQuery.page"
        :size.sync="listQuery.size"
        @pagination="changePageOption" />
    </div>
    <!-- 分页 -->
  </div>
</template>
<script>
import { getListPage
} from '@/api/cms/comprehensiveAnalysis/UnitCDIEvaluation'
import { findAllUnitDeptList, railtypeList, getDirection, getLineList } from '@/api/platform'
import { tableMixin } from '@/utils/public'
import { parseTime } from '@/utils'
export default {
  name: 'Name',
  components: {
  },
  mixins: [tableMixin],
  data() {
    return {
      // 表格高度
      height: 0,

      // 顶部操作栏配置
      filterData: {
        deptId: {
          clearable: true,
          key: 'unitDeptCode',
          type: 'select',
          title: '单位',
          placeholder: '请选择单位',
          options: [],
          props: { label: 'deptName', value: 'deptNo' }
        },
        lineId: {
          clearable: true,
          key: 'lineId',
          type: 'select',
          title: '线路',
          placeholder: '请选择线路',
          options: [],
          props: { label: 'seclineName', value: 'seclineId' }
        },
        directionId: {
          clearable: true,
          key: 'directionId',
          type: 'select',
          title: '行别',
          placeholder: '请选择行别',
          options: [],
          props: { label: 'directionName', value: 'directionId' }
        },
        beginTaskDate: {
          width: 'auto',
          key: 'beginTaskDate',
          type: 'date',
          dateType: 'date',
          valueFormat: 'yyyy-MM-dd',
          placeholder: '开始检测时间'
        },
        endTaskDate: {
          width: 'auto',
          key: 'endTaskDate',
          type: 'date',
          dateType: 'date',
          valueFormat: 'yyyy-MM-dd',
          placeholder: '结束检测时间'
        }
      },

      // 查询列表请求参数
      listQuery: {
        page: 1,
        lineId: null,
        unitDeptCode: null,
        railType: null,
        endTaskDate: null,
        beginTaskDate: null,
        directionId: null,
        size: 20,
        name: null
      },

      // 表格数组
      tableData: {
        loading: false,
        tableList: [],
        total: 0,
        columns: [
          { prop: 'deptName', label: '单位' },
          { prop: 'carNo', label: '检测车' },
          { prop: 'lineName', label: '线路' },
          { prop: 'directionName', label: '行别' },
          { prop: 'taskDate', label: '检测日期', formatter: row => parseTime(row.taskDate, '{y}-{m}-{d}') },
          { prop: 'beginMileage', label: '起始里程(km)' },
          { prop: 'endMileage', label: '终止里程(km)' },
          { prop: 'unitLenftg', label: '单元长度(km)' },
          { prop: 'avgSpeed', label: '锚段内平均速度(km/h)' },
          { prop: 'unitLenftg', label: '单元长度(km)' },
          { prop: 'arcingRate', label: '燃弧率' },
          { prop: 'cdis', label: 'CDIS' },
          { prop: 'cdih', label: 'CDIH' },
          { prop: 'cdif', label: 'CDIF' },
          { prop: 'cdia', label: 'CDIA' },
          { prop: 'cdi', label: 'CDI' },
          { prop: 'isEffective', label: '当前锚段得分是否有效' },
          { prop: 'isScore', label: 'CDI是否得分' }
        ],
        showIndex: true,
        showSelection: false,
        showOperation: false,
        showFilterColumn: false,
        operatonWidth: '160px',
        defaultOperations: [],
        hasAuth: true,
        rowShowColor: { name: 'name', value: 0 }
      },

      // 添加/编辑弹框
      dialog: {
        title: '',
        visible: false,
        disabled: false,
        loading: false,
        dataList: {
          lineList: []
        },
        form: {
          id: null,
          eqtName: null,
          eqtNo: null,
          contacts: null,
          contactsPhone: null,
          remark: null
        },
        initForm: {
          id: null,
          eqtName: null,
          eqtNo: null,
          contacts: null,
          contactsPhone: null,
          remark: null
        },
        rules: {
        }
      },

      // 查看弹框
      dialogLook: {
        visible: false
      }
    }
  },
  created() {
    this.getListPage()
    this.initPage()
  },
  activated() {
    this.getListPage()
    // this.getList()
  },
  mounted() {},
  methods: {
    // 获取下拉数据、字典
    getList() {
    },
    initPage() {
      // 获取单位 deptList
      findAllUnitDeptList({}).then(response => {
        var resData = response.data
        for (var i in resData) {
          if (resData[i].deptNo === '001200') {
            resData.splice(i, 1)
          }
        }
        this.filterData.deptId.options = Object.freeze(resData)
      })
      // findAllUnitDeptList({}).then(response => {
      //   this.filterData.deptId.options = Object.freeze(response.data)
      // })
      // 获取线路
      getLineList().then(response => {
        this.filterData.lineId.options = Object.freeze(response.data)
      })
      railtypeList().then(response => {
        this.filterData.railType.options = Object.freeze(response.data)
      })
      getDirection().then(response => {
        this.filterData.directionId.options = Object.freeze(response.data)
      })
    },
    // 查询信息列表
    getListPage() {
      this.tableData.loading = true
      getListPage(this.listQuery).then(response => {
        this.tableData.tableList = response.data.records
        this.tableData.total = response.data.total
        this.tableData.loading = false
      }).catch(() => {
        this.tableData.loading = false
      })
    },

    // 新增
    addForm() {
      const dialog = {
        title: '添加',
        type: 'add',
        visible: true,
        disabled: false,
        loading: false,
        form: JSON.parse(JSON.stringify(this.dialog.initForm)),
        dataList: {
          lineList: this.dialog.dataList.lineList
        }

      }

      this.dialog = Object.assign(this.dialog, dialog)
    },

    // 编辑
    updateForm(row, index) {
      this.currentRow = [row]
      const dialog = {
        title: '编辑',
        type: 'edit',
        visible: true,
        disabled: false,
        loading: false,
        dataList: {
          lineList: this.dialog.dataList.lineList
        },
        form: JSON.parse(JSON.stringify(row))
      }
      this.dialog = Object.assign(this.dialog, dialog)
    },

    view(row, index) { // 查看
      this.currentRow = [row]
      const dialog = {
        title: '查看',
        type: 'look',
        visible: false,
        disabled: false,
        loading: false,
        form: JSON.parse(JSON.stringify(row))
      }
      this.dialog = Object.assign(this.dialog, dialog)
      this.dialogLook.visible = true
    },

    // 查询
    search() {
      console.log(this.listQuery)
      this.listQuery.page = 1
      this.getListPage()
    },

    // 启用、停用,是否系统
    enable(row, $index) {
      this.rowIndex = $index
      this.updateData(row, 2)
    },

    // 改变分页配置
    changePageOption(data) {
      this.listQuery.page = data.page
      this.listQuery.size = data.size
      this.getListPage()
    },

    // 重置查询
    resetListQuery() {
      this.listQuery = {
        page: 1,
        lineId: null,
        unitDeptCode: null,
        railType: null,
        endTaskDate: null,
        beginTaskDate: null,
        directionId: null,
        size: 20
      }
      this.getListPage()
    }
  }
}
</script>
